package com.uwantsoft.util.paging;

import org.displaytag.properties.SortOrderEnum;

/**
 * @author ranyuanyuan
 */
public class AbstractOverviewQueryCondition {
    public static final int DEFAULT_OBJECT_PER_PAGE = 7;
    public static final String DEFAULT_SORT_BY = "desc";

    protected int page = 1;

    protected int objectsPerPag;
    //Sort field
    protected String sortCriterion;
    //Order: asc or desc
    protected String sortBy = DEFAULT_SORT_BY;

    public AbstractOverviewQueryCondition() {
        this(DEFAULT_OBJECT_PER_PAGE);
    }

    public AbstractOverviewQueryCondition(int objectsPerPag) {
        this.objectsPerPag = objectsPerPag;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getObjectsPerPage() {
        return objectsPerPag;
    }

    public void setObjectsPerPag(int objectsPerPag) {
        this.objectsPerPag = objectsPerPag;
    }

    public String getSortCriterion() {
        return sortCriterion;
    }

    public int getStartIndex() {
        return (getPage() - 1) * getObjectsPerPage();
    }

    public SortOrderEnum getSortDirection() {
        return SortOrderEnum.fromName(sortBy);
    }
}
